## $Id$
## Makefile.am for the TeX Live subdirectory ./doc/
##
## Copyright 2015-2020 Karl Berry <tex-live@tug.org>
## Copyright 2013-2015 Peter Breitenlohner <tex-live@tug.org>
## You may freely use, modify and/or distribute this file.
##
## The info files
info_TEXINFOS = tlbuild.texi
tlbuild_TEXINFOS = build-tools.txt \
  tlbuild-incl/install-tl.texi tlbuild-incl/tlmgr.texi

EXTRA_DIST = \
	README.solaris \
	splitinfo.gawk

# no reasonable way to avoid it with the pod doc.
MAKEINFOFLAGS = --set INFO_SPECIAL_CHARS_WARNING=0
MAKEINFOFLAGS += --disable-encoding

#  autogenerate the top-level README files.
readme-files: tlbuild.info
	rm -f README.*
	$(MAKEINFO) $(MAKEINFOFLAGS) --plaintext -o - $(srcdir)/tlbuild.texi \
	| tee /tmp/a \
	| gawk -f $(srcdir)/splitinfo.gawk
	ls -l README.*
#	head -8 README.*
readme-install: readme-files
	cp -p README.* $(top_srcdir)/
	svn diff $(top_srcdir)/README.* >/tmp/sd
	svn status $(top_srcdir)/README.*
#
.PHONY: readme-files readme-install script-links

#  autogenerate texinfo from install-tl and tlmgr pod.
# none of this is intended to be executed except manually.
mydoc = tlbuild

# Needs to be the pod2texi from at least Texinfo 6.3.
pod2texi = pod2texi
pod2texi_args = \
  --appendix-sections \
  --base-level=section \
  --no-fill-section-gaps \
  --preamble=''

# We use complicated section names in the tlmgr pod, and consequently
# complicated section references, schematically like this:
#   L<whatever|/mysec I<myital>>
# Unfortunately, the Pod module does not pass the necessary information
# in the callbacks to allow pod2texi to preserve the I<>.  It seems
# better to kludge in some substitutions here than reimplement a whole
# pod parser.  Sigh.
#
# The \@... in the replacements are escaping the @ in a Perl
# double-quote context, i.e., not an array.
# 
update_node_bad  = ref{tlmgr update [option...] [pkg...],
update_node_good = ref{tlmgr update [\@emph{option}...] [\@emph{pkg}...],
#
update_node_bad2  = [option...] [pkg...], update
update_node_good2  = [\@emph{option}...] [@emph{pkg}...], update
#
remove_node_bad = ref{tlmgr remove [option...] pkg...,
remove_node_good = ref{tlmgr remove [\@emph{option}...] \@emph{pkg}...,
#
install_node_bad = ref{tlmgr install [option...] pkg...,
install_node_good = ref{tlmgr install [\@emph{option}...] \@emph{pkg}...,

# we don't actually use the (autogenerated) -incl.texi file,
# but it makes for a convenient target.

# First make symlinks in build dir:
Master = $(top_srcdir)/../../Master
script-links:
	rm -f tlmgr.pl install-tl
	ln -s $(Master)/install-tl .
	ln -s $(Master)/texmf-dist/scripts/texlive/tlmgr.pl .

$(mydoc)-incl.texi: install-tl tlmgr.pl 
	$(pod2texi) -o $@ --subdir=$(mydoc)-incl $(pod2texi_args) $^
	cp $(mydoc)-incl/tlmgr.texi $(mydoc)-incl/tlmgr.texi.orig
	perl -pi \
          -e 's/\Q$(update_node_bad)\E/$(update_node_good)/' \
          -e ';s/\Q$(update_node_bad2)\E/$(update_node_good2),/' \
          -e ';' \
          -e 's/\Q$(remove_node_bad)\E/$(remove_node_good)/' \
          -e ';' \
          -e 's/\Q$(install_node_bad)\E/$(install_node_good)/' \
	  $(mydoc)-incl/tlmgr.texi
	cp $(mydoc)-incl/tlmgr.texi $(srcdir)/$(mydoc)-incl/
	cp $(mydoc)-incl/install-tl.texi $(srcdir)/$(mydoc)-incl/
.PHONY: $(mydoc)-incl.texi
